
// // 获取当前选项卡ID
function getCurrentTabId(callback)
{
	chrome.tabs.query({active: true, currentWindow: true}, function(tabs)
	{
		if(callback) callback(tabs.length ? tabs[0].id: null);
	});
}

// 向content-script注入JS片段
function executeScriptToCurrentTab(code)
{
	getCurrentTabId((tabId) =>
	{
		chrome.tabs.executeScript(tabId, {code: code});
	});
}

// csdn！
$('#update_bg_color').click(() => {
    executeScriptToCurrentTab('document.getElementsByClassName("meau-gotop-box")[0].style.display="none";')
    executeScriptToCurrentTab('document.getElementsByClassName("recommend-right")[0].style.display="none";')
    executeScriptToCurrentTab('document.getElementsByClassName("recommend-left")[0].style.display="none";')
	executeScriptToCurrentTab('document.getElementsByTagName("aside")[0].style.display="none";')
    executeScriptToCurrentTab('document.getElementsByTagName("main")[0].style.width="100%";')
    executeScriptToCurrentTab('document.getElementsByClassName("pulllog-box")[0].style.display="none";')
    executeScriptToCurrentTab('var ifs = document.getElementsByTagName("iframe");' +
		'for(var i = 0;i<ifs.length;i++){ifs[i].style.display="none";};')
    executeScriptToCurrentTab('document.getElementsByClassName("tool-box")[0].style.display="none";')
    executeScriptToCurrentTab('document.getElementsByClassName("ad-widget-imageplus-sticker")[0].style.display="none";')
});

// csdn！ 还原
$('#re_csdn').click(() => {
    executeScriptToCurrentTab('document.getElementsByClassName("meau-gotop-box")[0].style.display="block";')
    executeScriptToCurrentTab('document.getElementsByClassName("recommend-right")[0].style.display="block";')
    executeScriptToCurrentTab('document.getElementsByClassName("recommend-left")[0].style.display="block";')
    executeScriptToCurrentTab('document.getElementsByTagName("aside")[0].style.display="block";')
    executeScriptToCurrentTab('document.getElementsByTagName("main")[0].style.width="";')
    executeScriptToCurrentTab('document.getElementsByClassName("pulllog-box")[0].style.display="block";')
    executeScriptToCurrentTab('var ifs = document.getElementsByTagName("iframe");' +
        'for(var i = 0;i<ifs.length;i++){ifs[i].style.display="block";};')
    executeScriptToCurrentTab('document.getElementsByClassName("tool-box")[0].style.display="block";')
    executeScriptToCurrentTab('document.getElementsByClassName("ad-widget-imageplus-sticker")[0].style.display="block";')
});


$('#bg0p').click(() => {
    var cc = 'document.getElementsByTagName("a")[0].style.display="none"';
    executeScriptToCurrentTab(cc);
});

//ad开头的类 不能为html或者body
$('#clean_ad_all').click(() => {
    var cc = " var bs = $(\"[class*='ad']\");\n" +
        "    var bs1 = $(\"[id*='ad']\");\n" +
        "    for(var i=0;i<bs1.length;i++){\n" +
        "       if(bs1[i].tagName=='HTML'||bs1[i].tagName=='BODY')continue;\n" +
        "      bs1[i].style.display='none';\n" +
        "    };\n"+
        "    for(var i=0;i<bs.length;i++){\n" +
        "       if(bs[i].tagName=='HTML'||bs[i].tagName=='BODY')continue;\n" +
        "      bs[i].style.display='none';\n" +
        "    }";
    executeScriptToCurrentTab(cc);
});
//还原ad开头的类
$('#re_ad_all').click(() => {
    var cc = " var bs = $(\"[class*='ad']\");\n" +
        "    var bs1 = $(\"[id*='ad']\");\n" +
        "    for(var i=0;i<bs1.length;i++){\n" +
        "       bs1[i].style.display='block';\n" +
        "    };\n"+
        "    for(var i=0;i<bs.length;i++){\n" +
        "       bs[i].style.display='block';\n" +
        "    }";
    executeScriptToCurrentTab(cc);
});


//ad-/ad_开头的类 不能为html或者body
$('#clean_ad').click(() => {
    var cc = " var bs = $(\"[class^='ad']\");\n" +
        "    var bs1 = $(\"[id^='ad']\");\n" +
        "    for(var i=0;i<bs1.length;i++){\n" +
        "       if(bs1[i].tagName=='HTML'||bs1[i].tagName=='BODY')continue;\n" +
        "      bs1[i].style.display='none';\n" +
        "    };\n"+
        "    for(var i=0;i<bs.length;i++){\n" +
        "       if(bs[i].tagName=='HTML'||bs[i].tagName=='BODY')continue;\n" +
        "      bs[i].style.display='none';\n" +
        "    }";
    executeScriptToCurrentTab(cc);
});
//还原ad-/ad_开头的类
$('#re_ad').click(() => {
    var cc = " var bs = $(\"[class^='ad']\");\n" +
        "    var bs1 = $(\"[id^='ad']\");\n" +
        "    for(var i=0;i<bs1.length;i++){\n" +
        "       bs1[i].style.display='block';\n" +
        "    };\n"+
        "    for(var i=0;i<bs.length;i++){\n" +
        "       bs[i].style.display='block';\n" +
        "    }";
    executeScriptToCurrentTab(cc);
});

//
// $('#bgp').click(() => {
//     var src = "document.getElementsByTagName(\"html\")[0].style.backgroundColor=\"green\";";
//     executeScriptToCurrentTab(src);
// });



//去掉iframe
$('#clean_if').click(() => {
    executeScriptToCurrentTab('var ifs = document.getElementsByTagName("iframe");' +
        'for(var i = 0;i<ifs.length;i++){ifs[i].style.display="none";};')
});
//还原iframe
$('#re_if').click(() => {
    executeScriptToCurrentTab('var ifs = document.getElementsByTagName("iframe");' +
        'for(var i = 0;i<ifs.length;i++){ifs[i].style.display="block";};')
});
